package com.yuwei.module_patrol.adapter

import android.graphics.Color
import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.yuwei.http.entity.PatrolEntityItem
import com.yuwei.http.entity.PatrolPointsEntityItem
import com.yuwei.module_patrol.R

class PatrolAdapter : BaseQuickAdapter<PatrolEntityItem, BaseViewHolder>(
    R.layout.patrol_item
) {
    private var list = mutableListOf<PatrolPointsEntityItem>()
    var adapter = PointsAdapter()
    fun setList(list: MutableList<PatrolPointsEntityItem>) {
        this.list = list
    }
    override fun convert(holder: BaseViewHolder, item: PatrolEntityItem) {
        val view = holder.getView<RecyclerView>(R.id.patrol_item_rv)
        adapter.data.clear()
        if(list.size!=0){
            adapter.data.addAll(list)
            adapter.notifyDataSetChanged()
        }
        view.adapter = adapter
        view.layoutManager = LinearLayoutManager(view.context,LinearLayoutManager.HORIZONTAL,false)
        holder.setText(R.id.patrol_item_name, item.patrolPerson)
            .setText(R.id.patrol_item_time, item.patrolTime)
        when(item.patrolPersonId){
            2->{
                holder.setText(R.id.patrol_item_zw,"安保部主管")
            }
            else->{
                holder.setText(R.id.patrol_item_zw,"安保人员")
            }
        }
        val textView = holder.getView<TextView>(R.id.patrol_item_type)
        when(item.patrolStatus){
            "1"->{
                holder.setText(R.id.patrol_item_type,"未完成")
                textView.setTextColor(Color.parseColor("#16A34A"))
                textView.setBackgroundResource(R.drawable.patrol_status_bg)
            }
            "2"->{
                holder.setText(R.id.patrol_item_type,"进行中")
                textView.setTextColor(Color.parseColor("#CA8A04"))
                textView.setBackgroundResource(R.drawable.patrol_status_bg2)
            }
        }

    }
}